package org.moonshiner.controller.mock;

import org.springframework.beans.BeansException;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

import org.moonshiner.controller.Application;
import org.moonshiner.controller.svn.SVNRepositoryProvider;
import org.moonshiner.model.context.AppContext;

public class MockRepository {

	public static SVNRepository getMockRepository() {
		SVNRepository repository = null;
		ISVNAuthenticationManager authenticationManager = SVNWCUtil
				.createDefaultAuthenticationManager("Roston", "msgtvp9cp");
		((DefaultSVNAuthenticationManager) authenticationManager)
				.setAuthenticationForced(true);
		try {
			repository = ((SVNRepositoryProvider) AppContext.getAppContext()
					.getBean(SVNRepositoryProvider.BEAN_NAME))
					.initRepository(Application.SVN_REPOSITORY_URL);
		} catch (BeansException e) {
			e.printStackTrace();
		} catch (SVNException e) {
			e.printStackTrace();
		}
		repository.setAuthenticationManager(authenticationManager);

		return repository;
	}

}
